
#include "../include/types.h"
#include "../include/const.h"
#include "../include/monitor.h"
#include "../include/task.h"
#include "../include/console.h"
#include "../include/process.h"

void init() {
	monitor_write("Initialazing IDE: ");
  init_ide();
	monitor_color(GREEN);
  monitor_write("OK\n");
	monitor_color(DEFAULT_COLOR);
	
	monitor_write("Initialazing EXT2: ");
  if(!init_ext2()){
		monitor_color(RED);
    monitor_write("ERROR\n");
		monitor_color(DEFAULT_COLOR);
  }
	monitor_color(GREEN);
  monitor_write("OK\n");
	monitor_color(DEFAULT_COLOR);
	
	monitor_write("Initialazing CMD... \n");
	
	/* Wait */
	int i;
	for (i = 1; i < 100000000; i++) ;
	for (i = 1; i < 20000000; i++) ;
	
  init_cmd();
	
	for(;;);
}

/* Testai */
void test1() {
	for (;;) {
		int i;
		for (i = 1; i < 1000000; i++);
		print("TEST1", current_task()->console);
	}
}

void test2() {
	for (;;) {
		int i;
		for (i = 1; i < 1000000; i++);
		print("TEST2", current_task()->console);
    getchar();
	}
}

void proc() {
	task_t *c_task;
	task_t *t_task;
	c_task = current_task();
	t_task = c_task->next;
	
	print("PID    Name    Father    Childs\n", current_task()->console);
	while (t_task != c_task) {
		print("  ", current_task()->console);
		print_dec(t_task->id, current_task()->console);
		print("     ", current_task()->console);
		print(t_task->name, current_task()->console);
		if (t_task->father != NULL) {
			print("      ", current_task()->console);
			print_dec(t_task->father->id, current_task()->console);
		} else {
			print("      -", current_task()->console);
		}
		if (t_task->childs != NULL) {
			print("        Yes", current_task()->console);
		} else {
			print("        No", current_task()->console);
		}
		print("\n", current_task()->console);
		t_task = t_task->next;
	}
	print("  ", current_task()->console);
	print_dec(t_task->id, current_task()->console);
	print("     ", current_task()->console);
	print(t_task->name, current_task()->console);
	print("      ", current_task()->console);
	print_dec(t_task->father->id, current_task()->console);
  print("        No", current_task()->console);
	print("\n", current_task()->console);
	finish_task();
}

void prog() {
	int i;
	char input[256];
	char tmp;
	boolean finished;
	i = 0;
	finished = FALSE;
	
	print("\nIveskite simboliu eilute:\n", current_task()->console);
	tmp = getchar();
	while (!finished) {
		if (tmp == ' ') {
			finished = TRUE;
		} else {
			input[i] = tmp;
			i++;
			tmp = getchar();
		}
	}
	print("\nJusu ivestas tekstas:\n", current_task()->console);
	for (;;) {
		for (i = 1; i < 10000000; i++);
		print(input, current_task()->console);
		print("\n", current_task()->console);
	}
}
